package com.link.base.base.system.controller;

import com.link.base.base.system.model.DelBackups;
import com.link.base.base.system.service.DelBackupsService;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author LiYang
 * @date 20190521
 *
 * 删除备份通用控制器
 */
@Controller
@RequestMapping("/link/delBackups/")
public class DelBackupsController extends BasicController<DelBackups> {

    @Resource
    private DelBackupsService delBackupsService;

    @Override
    public BasicService<DelBackups> getBasicService() {
        return delBackupsService;
    }

    /**
     * @author LiYang
     * @date 20190522
     *
     * 还原删除的记录
     */
    @RequestMapping(value = "/revert", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public Map<String, Object> revert(@RequestBody List<DelBackups> delBackupsList, HttpSession session,
                                      HttpServletRequest request, HttpServletResponse response) {
        HashMap<String, Object> result = new HashMap<>(4);
        try {
            delBackupsService.revert(delBackupsList);
            result.put("success", true);
            result.put("code", "200");
        } catch (Exception e) {
            result.put("success", false);
            result.put("result", "还原时出现异常！");
            result.put("code", "400");
        }
        return result;
    }

    /**
     * @author LiYang
     * @date 20190522
     *
     * 还原删除的记录
     */
    @RequestMapping(value = "/batchDelete", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public Map<String, Object> batchDelete(@RequestBody List<DelBackups> delBackupsList, HttpSession session,
                                      HttpServletRequest request, HttpServletResponse response) {
        HashMap<String, Object> result = new HashMap<>(4);
        try {
            delBackupsService.batchDelete(delBackupsList);
            result.put("success", true);
            result.put("code", "200");
        } catch (Exception e) {
            result.put("success", false);
            result.put("result", "删除数据出现异常！");
            result.put("code", "400");
        }
        return result;
    }
}
